from django import template
from blog.models import Category
from django.core.urlresolvers import resolve

register = template.Library()

@register.inclusion_tag('blog/_menu.html', takes_context = True)
def partial_render_right_menu(context):
    categories = Category.objects.all()

    request = context['request']
    match = resolve(request.path)

    current_category = match.url_name == 'category_detail' and (match.kwargs['category_id'],) or ('999',)
    current_category = int(current_category[0])

    return {
        'categories'       : categories,
        'url_name'         : match.url_name,
        'current_category' : current_category,
    }
